using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;

namespace UsersBirthdays_HireDates.Features.Feature1
{

    [Guid("c8d5f0fc-44fe-4f86-8343-15f42b888825")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == "BirthdayssHiresDays")
                {
                    job.Delete();
                }
            }
            //--
            theJob listLoggerJob = new theJob("BirthdayssHiresDays", site.WebApplication);
            SPDailySchedule schedule = new SPDailySchedule();

            schedule.BeginHour = 23;
            schedule.BeginMinute = 0;
            schedule.BeginSecond = 0;
            schedule.EndHour = 23;
            schedule.EndMinute = 59;
            schedule.EndSecond = 59;

            listLoggerJob.Schedule = schedule;
            listLoggerJob.Update();
        }



        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == "BirthdayssHiresDays")
                {
                    job.Delete();
                }
            }
        }
    }
}
